/*
 * Created by Jaren at 2022/01/29 16:52
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:inmotion_protocol_example/module/base/base.dart';
import 'package:inmotion_protocol_example/module/fw_update/fw_update_controller.dart';

class FwUpdatePage extends BaseView<FwUpdateController> {

    _buildActionViews(FwUpdateController controller) {
        return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
                Wrap(children: [

                    MaterialButton(onPressed: () => {controller.startUpdate()}, child: const Text('START'),),

                    MaterialButton(onPressed: () => {controller.cancelUpdate()}, child: const Text('CANCEL'),),

                    Obx(() => Text(controller.updateStatus.value)),

                ],),
            ],
        );
    }

    @override
    Widget build(BuildContext context) {
        super.build(context);
        return WillPopScope(child: Scaffold(
            appBar: AppBar(
                title: const Text("FW Update"),
            ),
            body: Column(
                children: [
                    Expanded(
                        child: Column(
                            mainAxisSize: MainAxisSize.min,
                            children: [ _buildActionViews(controller),],
                        ),
                    ),
                ],
            )), onWillPop: () => _onBackPressed(controller));
    }


    Future<bool> _onBackPressed(FwUpdateController controller) {
        return Future.value(true);
    }
}